package demo.Socket.Upload_picture;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/20-08-20-14:41
 * @Description：demo.Socket.Upload_picture
 */
public class Uplading_Client {
    public static void main(String[] args) {
        Socket socket = null;
        FileInputStream in = null;
        OutputStream writer = null;
        try {
            socket= new Socket("127.0.0.1",6677);
            in= new FileInputStream("C:\\Users\\hjy\\Pictures\\jjy3.jpg");
            writer = socket.getOutputStream();
            int len =-1;
            byte[] b = new byte[1024];
            while((len = in.read(b))!= -1){
                writer.write(b,0,len);
            }
            System.out.println("上传成功！");
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if(in != null){
                    in.close();
                }
                if(writer != null){
                    writer.close();
                }
                if(socket != null){
                    socket.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
